﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System.Text;
using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using QUT.Bio.TagService;
using QUT.Bio.Util;

namespace QUT.Bio.Tags {
	public class WrappedRdfTag : IComparable<WrappedRdfTag>, ISelectable {
		public RdfTag Tag {
			get;
			private set;
		}

		public WrappedRdfTag ( RdfTag tag ) {
			Tag = tag;
		}

		public int CompareTo ( WrappedRdfTag other ) {
			int result = Tag.TagLabelName.CompareTo( other.Tag.TagLabelName );

			if ( result == 0 ) {
				result = Tag.TagPredicateUri.CompareTo( other.Tag.TagPredicateUri );
			}

			if ( result == 0 ) {
				result = Tag.TagObjectUri.CompareTo( other.Tag.TagObjectUri );
			}

			return result;
		}

		public int CompareTo ( object other ) {
			return other is WrappedRdfTag ? CompareTo( (WrappedRdfTag) other ) : -1;
		}

		public override bool Equals ( object obj ) {
			return obj is WrappedRdfTag ? 0 == CompareTo( (WrappedRdfTag) obj ) : false;
		}

		public override int GetHashCode () {
			return Tag.TagLabelName.GetHashCode() << 5 + Tag.TagPredicateUri.GetHashCode() << 3 + Tag.TagObjectUri.GetHashCode();
		}

		public bool Matches ( string tagLabel, string predicateUri, string objectUri ) {
			return Tag.TagLabelName == tagLabel && Tag.TagPredicateUri == predicateUri && Tag.TagObjectUri == objectUri;
		}

		public override string ToString () {
			StringBuilder s = new StringBuilder( Tag.TagLabelName );

			if ( Tag.TagPredicateUri == Tags.PredicateTermMeans ) {
				s.Append( '[' );
				s.Append( Tags.NamespaceOf( Tag.TagObjectUri ) );
				s.Append( ']' );
			}

			return s.ToString();
		}

		public string SelectableText {
			get { return ToString(); }
		}

		#region ISelectable Members

		public bool Selected {
			get {
				throw new NotImplementedException();
			}
			set {
				throw new NotImplementedException();
			}
		}

		#endregion

#pragma warning disable 67
		public event System.ComponentModel.PropertyChangedEventHandler  PropertyChanged;
#pragma warning restore 67
	}
}
